﻿@using RuoVea.ExUtil;

@using Microsoft.Extensions.Options

@{
    ViewData["Title"] = "作业";
    string JobRootUrl = "";
    Layout = "";
}
<!DOCTYPE html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewData["Title"] - MES管理系统</title>
    <link href="/elementui/index.css" rel="stylesheet" />
    <link href="/elementui/index.extend.css?v=22" rel="stylesheet" />
    <style scoped>


    </style>
</head>
<body>

    <div id="main" v-cloak>
    

        <el-main>
            <el-row type="flex" align="center">
                <el-col :span="18">
                    <el-form :inline="true" :model="tableQuery.filter">
                        <el-form-item prop="jobName" label="任务名称">
                            <el-input v-model="tableQuery.filter.jobName" placeholder="任务名称" size="mini"></el-input>
                        </el-form-item>
                        <el-form-item prop="jobName" label="分组名称">
                            @* <el-input v-model="tableQuery.filter.jobGroup" placeholder="分组名称" size="mini"></el-input> *@
                            <el-select v-model="tableQuery.filter.jobGroup" clearable placeholder="请选择" size="mini">
                                <el-option key="default" label="默认" value="default"></el-option>
                                <el-option key="dev" label="开发区" value="dev"></el-option>
                                <el-option key="test" label="测试区" value="test"></el-option>
                                <el-option key="verify" label="验证区" value="verify"></el-option>
                                <el-option key="official" label="正式区" value="official"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="jobName" label="启用/禁用">
                            <el-select v-model="tableQuery.filter.status" clearable placeholder="请选择" size="mini">
                                <el-option key="0" label="启用" value="0"></el-option>
                                <el-option key="1" label="禁用" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="jobName">
                            <el-button type="primary" size="mini" icon="el-icon-search"  v-on:click="OnLoadJobs">查询</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
                <el-col :span="5" style="text-align: right;">
                    <el-button type="primary" size="mini" icon="el-icon-plus" @@click="addDialogForm">新建任务</el-button>
                    <el-button type="default" size="mini" icon="el-icon-refresh" v-on:click="OnLoadJobs">刷新数据</el-button>
                </el-col>
            </el-row>
            <el-row type="flex" align="center">
                <el-col :span="24">
                    <el-table :data="tableData"
                              border stripe style="width: 100%;" size="small"
                              v-loading="loading">
                        <el-table-column v-for="(column, index) in columns"
                                         :key="index"
                                         :prop="column.prop"
                                         :label="column.label"
                                         :width="column.width"></el-table-column>

                        <el-table-column width="260" label="操作" fixed="right">
                            <template slot-scope="scope">
                                <el-tooltip content="查看记录" placement="bottom">
                                    <el-button type="default" size="mini" icon="el-icon-view" v-on:click="logDialog(scope.$index, scope.row)"></el-button>
                                </el-tooltip>
                                <el-tooltip content="修改记录" placement="bottom">
                                    <el-button type="primary" size="mini" icon="el-icon-edit" v-on:click="editDialogForm(scope.$index, scope.row)"></el-button>
                                </el-tooltip>
                                <el-tooltip content="删除记录" placement="bottom">
                                    <el-button type="danger" size="mini" icon="el-icon-delete-solid" v-on:click="handleDelete(scope.$index, scope.row)"></el-button>
                                </el-tooltip>
                                <slot name="toolbutton"></slot>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination @@size-change="handleSizeChange" @@current-change="handleCurrentChange" :current-page="tableQuery.pageNo" :page-sizes="[10, 20, 30, 40, 50]" :page-size="tableQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="tableQuery.totalRows"></el-pagination>
                </el-col>
            </el-row>
        </el-main>
        @* // *@
    </div>

    <script type="text/javascript" src="/vue/vue.js?v=2.0"></script>
    <script type="text/javascript" src="/vue/vue-i18n.min.js?v=2.0"></script>
    <script type="text/javascript" src="/elementui/index.js"></script>
    <script type="text/javascript" src="/elementui/index.extend.js"></script>
    <script type="text/javascript" src="/vue/axios.min.js"></script>
    <script>
        Vue.component('ElExtendBody', {
            props: {
                logoSrc: String,
                logoTitle: String,
                activeIndex: { type: String, },
                menuData: Array,
                userName: String,
                userAvatar: String,
                loginOutTxt: String,
                handleLogout: Function,
            },
            template: ``
        });
        var $taskVue = new Vue({
            el: "#main",
            data() {
                return {
                    tableData: [
                        {
                            date: '2016-05-03',
                            name: 'Tom',
                            address: 'No. 189, Grove St, Los Angeles',
                        }, {
                            date: '2016-05-02',
                            name: 'Tom2',
                            address: 'No. 189, Grove St, Los Angeles2',
                        },
                    ],
                    columns: [
                        {
                            prop: "date",
                            label: "日期",
                            width: 180
                        },
                        {
                            prop: "name",
                            label: "姓名",
                            width: 180
                        },
                        {
                            prop: "address",
                            label: "地址"
                        },
                    ],
                    loading: false,
                    filter: [
                        {
                            type: 'input', // 表单项类型
                            label: '姓名', // 标签文本
                            prop: 'name',  // 表单项的属性名，对应 model 中的字段
                            rules: [{ required: true, message: '姓名不能为空', trigger: 'blur' }] // 校验规则
                        },
                        {
                            type: 'select',
                            label: '性别',
                            prop: 'gender',
                            options: [ // 选择项列表
                                { label: '男', value: 'male' },
                                { label: '女', value: 'female' }
                            ],
                            rules: [{ required: true, message: '性别不能为空' }]
                        },
                        // ...其他表单项配置
                    ],
                    tableQuery: {
                        pageNo: 1,
                        pageSize: 10,
                        totalRows: 0,
                        filter: {
                            jobName: '',
                            jobGroup: "",
                            status: ""
                        }
                    },
                }
            },
            created() {
                // setInterval(() => { this.OnLoadJobs(); }, 10000);
            },
            mounted: function () {
                // this.OnLoadJobs();
            },
            methods: {
                handleEdit(index, row) {
                    // 编辑操作的逻辑
                },
                handleDelete(index, row) {
                    // 删除操作的逻辑
                },
                LoadData() {
                    var that = this;
                    that.loading = true;
                    axios.post("@("/jobList")", that.tableQuery)
                        .then(function (res) {
                            that.tableData = res.data.data.rows;
                            that.tableQuery.totalRows = res.data.data.totalRows;
                            that.loading = false;
                        }).catch(function (res) { that.loading = false; });
                },
                handleSizeChange(val) { var that = this; that.tableQuery.pageNo = 1; that.tableQuery.pageSize = val; that.OnLoadJobs(); },
                handleCurrentChange(val) { var that = this; that.tableQuery.pageNo = val; that.OnLoadJobs(); },

                addDialogForm() {
                    var that = this;
                    that.dialogFormVisible = true; that.dialogForm = null;
                    that.dialogForm = that.dialogInitForm;
                },
                editDialogForm(index, row) {
                    var that = this;
                    that.dialogFormVisible = true;
                    that.dialogForm = that.dialogInitForm;
                    axios("@("/" + JobRootUrl + "/getjob/")" + row.id).then(function (res) { if (res.data.code == 200) { that.dialogForm = res.data.data; } });
                },
                logDialog(index, row) { var that = this; window.location.href = "@("/" + JobRootUrl + "/log?id=")" + row.id; },
                handleDelete(index, row) {
                    var that = this;
                    this.$confirm('确定删除此任务?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
                        axios("@("/" + JobRootUrl + "/remove/")" + row.id).then(function (res) {
                            if (res.data.code == 200) {
                                that.$message({ message: res.data.message, center: true, type: 'success' });
                                rows.splice(index, 1);
                                that.OnLoadJobs();
                            } else {
                                that.$message({ message: res.data.message, center: true, type: 'error' });
                            }
                        });
                    });
                }
            },
            filters: {
                scheduleTypeTitle(data) {
                    return data.scheduleTypeText + ":" + data.runTypeText;
                }
            }
        });
    </script>
</body>
</>
